function love.load()
	board = {   -- 定义小球运动边框
		x = 300, 
		y = 100,
		w = 750,
		h = 550
	}
	menu = {
	    image = love.graphics.newImage("image/love.png"),  -- 三张替换背景图片图片
		image1 = love.graphics.newImage("image/love1.png"),
		image2 = love.graphics.newImage("image/love2.png"),
		position1 = false,   -- 判断鼠标是否在各矩形框内
		position1_1 = false, position1_2 = false, position1_3 = false, position1_4 = false,
		position2 = false,
		position2_1 = false, position2_2 = false,
		down1 = false,    -- 判断鼠标是否按下
		down1_1 = false, down1_4 = false, down1_4 = false, down1_4 = false,
		down2_1 = false, down2_2 = false,
		down2 = false,
		temp = 1,  -- 判断哪张图片为背景
		button = 0,    -- 判断在哪个菜单栏下
		key = false,   -- 判断鼠标按下
		over = 0
		}
	question1 = {x = 50, y = 200, w = 250, h = 300}  -- 各矩形框位置
	question1_1 = {x = 50, y = 200, w = 125, h = 250}
	question1_2 = {x = 150, y = 200, w = 225, h = 250}
	question1_3 = {x = 50, y = 275, w = 125, h = 325}
	question1_4 = {x = 150, y = 275, w = 225, h = 325}
	question2 = {x = 50, y = 400, w = 250, h = 500}
	question2_1 = {x = 50,y = 400, w = 125, h = 450}
	question2_2 = {x = 150, y = 400, w = 225, h = 450 }
	ball = {         -- 小球参数
		x = 500,
		y = 300,
		r = 5, -- 小球半径
		length = 3, -- 匀速运动
	}
	font = love.graphics.newFont(40)  -- 字体设置
	font1 = love.graphics.newFont(20)
end
function keyTest()  -- 判断键盘是否输入，更新小球坐标
	local down = love.keyboard.isDown --方便书写，而且会加快一些速度
	if down("a") and (ball.x - ball.r) > board.x then
		ball.x = ball.x - ball.length
	elseif down("d") and (ball.x + ball.r) < board.w then
		ball.x = ball.x + ball.length
	elseif down("w") and (ball.y - ball.r) > board.y then
		ball.y = ball.y - ball.length
	elseif down("s") and (ball.y + ball.r) < board.h then
		ball.y = ball.y + ball.length
	end
end

-- 判断鼠标位置是否进入矩形框中
function position_check(tx, ty, x, y, w, h)
    if tx > x and tx < w and ty > y and ty < h then
	    return true
	else 
	    return false
	end
end
-- 判断为哪个菜单以及鼠标是否在矩形内
function mouseControl()
	local targetx,targety = love.mouse.getPosition()
	if menu.button == 0 then  -- button == 0
	    menu.position1 = position_check(targetx, targety, question1.x, question1.y, question1.w, question1.h)
		menu.position2 = position_check(targetx, targety, question2.x, question2.y, question2.w, question2.h)
	elseif menu.button == 1 then -- button == 1
		menu.position1_1 = position_check(targetx, targety, question1_1.x, question1_1.y, question1_1.w, question1_1.h)
		menu.position1_2 = position_check(targetx, targety, question1_2.x, question1_2.y, question1_2.w, question1_2.h)
		menu.position1_3 = position_check(targetx, targety, question1_3.x, question1_3.y, question1_3.w, question1_3.h)
		menu.position1_4 = position_check(targetx, targety, question1_4.x, question1_4.y, question1_4.w, question1_4.h)
	elseif menu.button == 2 then  -- button == 2
	    menu.position2_1 = position_check(targetx, targety, question2_1.x, question2_1.y, question2_1.w, question2_1.h)
		menu.position2_2 = position_check(targetx, targety, question2_2.x, question2_2.y, question2_2.w, question2_2.h)
	end
end
-- 检测鼠标按下
function love.mousepressed(x, y, key)
	if key == 1 then
	    menu.key = true
	end
end
-- 判断鼠标是否按到按钮
function check(down, position)
    if not down and menu.key and position then
	    return true
	else 
	    return false
	end
end

function love.update()
	keyTest()   -- 键盘输入
	mouseControl()  -- 鼠标是否在矩形框内
	-- 判断鼠标是否在各矩形框内
	if menu.button == 0 then  
	    menu.down1 = check(menu.down1, menu.position1)
		menu.down2 = check(menu.down2, menu.position2)
	elseif menu.button == 1 then
	    menu.down1_1 = check(menu.down1_1, menu.position1_1)
		menu.down1_2 = check(menu.down1_2, menu.position1_2)
		menu.down1_3 = check(menu.down1_3, menu.position1_3)
		menu.down1_4 = check(menu.down1_4, menu.position1_4)
	elseif menu.button == 2 then
	    if menu.over == 1 then
	       love.event.push("quit")
	    end
	    menu.down2_1 = check(menu.down2_1, menu.position2_1)
		menu.down2_2 = check(menu.down2_2, menu.position2_2)
	end
	menu.key = false
end

function love.draw()
    
    love.graphics.setColor(255, 250, 250, 100)
	love.graphics.rectangle("fill", 0, 0, 800, 600)
	-- 图形界面设置，选择背景
	if menu.temp == 1 then 
	    love.graphics.draw(menu.image, board.x, board.y)
	elseif menu.temp == 2 then
	    love.graphics.draw(menu.image1, board.x, board.y)
	elseif menu.temp == 3 then
	    love.graphics.draw(menu.image2, board.x, board.y)
	end
	-- 菜单界面设置
	if menu.button == 1 then  -- change菜单，四个选项
	    if not menu.position1_1 then 
	        love.graphics.setColor(0, 205, 205, 100)   
		    love.graphics.rectangle("fill", question1_1.x, question1_1.y , question1_1.w - question1_1.x, question1_1.h - question1_1.y, 10, 10)
		    love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("style1", 60, 212)
		elseif menu.down1_1 then
		    love.graphics.setColor(0, 255, 0)
			love.graphics.rectangle("fill", question1_1.x, question1_1.y , question1_1.w - question1_1.x, question1_1.h - question1_1.y, 10, 10)
		    menu.temp = 1
			love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("style1", 60, 212)
		elseif menu.position1_1 then
		    love.graphics.setColor(255, 0, 0)
			love.graphics.rectangle("fill", question1_1.x, question1_1.y , question1_1.w - question1_1.x, question1_1.h - question1_1.y, 10, 10)
	        love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("style1", 60, 212)
		end -- 1
		if not menu.position1_2 then 
	        love.graphics.setColor(0, 205, 205, 100)   
		    love.graphics.rectangle("fill", question1_2.x, question1_2.y , question1_2.w - question1_2.x, question1_2.h - question1_2.y, 10, 10)
		    love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("style2", 160, 212)
		elseif menu.down1_2 then
		    love.graphics.setColor(0, 255, 0)
			love.graphics.rectangle("fill", question1_2.x, question1_2.y , question1_2.w - question1_2.x, question1_2.h - question1_2.y, 10, 10)
		    menu.temp = 2
			love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("style2", 160, 212)
		elseif menu.position1_2 then
		    love.graphics.setColor(255, 0, 0)
			love.graphics.rectangle("fill", question1_2.x, question1_2.y , question1_2.w - question1_2.x, question1_2.h - question1_2.y, 10, 10)
	        love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("style2", 160, 212)
		end -- 2
		if not menu.position1_3 then 
	        love.graphics.setColor(0, 205, 205, 100)   
		    love.graphics.rectangle("fill", question1_3.x, question1_3.y , question1_3.w - question1_3.x, question1_3.h - question1_3.y, 10, 10)
		    love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("style3", 60, 287)
		elseif menu.down1_3 then
		    love.graphics.setColor(0, 255, 0)
			love.graphics.rectangle("fill", question1_3.x, question1_3.y , question1_3.w - question1_3.x, question1_3.h - question1_3.y, 10, 10)
		    menu.temp = 3
			love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("style3", 60, 287)
		elseif menu.position1_3 then
		    love.graphics.setColor(255, 0, 0)
			love.graphics.rectangle("fill", question1_3.x, question1_3.y , question1_3.w - question1_3.x, question1_3.h - question1_3.y, 10, 10)
	        love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("style3", 60, 287)
		end -- 3
		if not menu.position1_4 then 
	        love.graphics.setColor(0, 205, 205, 100)   
		    love.graphics.rectangle("fill", question1_4.x, question1_4.y , question1_4.w - question1_4.x, question1_4.h - question1_4.y, 10, 10)
		    love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("cancle", 155, 287)
		elseif menu.down1_4 then
		    love.graphics.setColor(0, 255, 0)
			love.graphics.rectangle("fill", question1_4.x, question1_4.y , question1_4.w - question1_4.x, question1_4.h - question1_4.y, 10, 10)
		    menu.button = 0
			love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("cancle", 155, 287)
		elseif menu.position1_4 then
		    love.graphics.setColor(255, 0, 0)
			love.graphics.rectangle("fill", question1_4.x, question1_4.y , question1_4.w - question1_4.x, question1_4.h - question1_4.y, 10, 10)
	        love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("cancle", 155, 287)
		end -- 4
	elseif menu.button == 2 then  -- exit菜单，两个选项
	    if not menu.position2_1 then 
	        love.graphics.setColor(0, 205, 205, 100)   
		    love.graphics.rectangle("fill", question2_1.x, question2_1.y , question2_1.w - question2_1.x, question2_1.h - question2_1.y, 10, 10)
		    love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("Exit", 68, 412)
		elseif menu.down2_1 then
		    love.graphics.setColor(0, 255, 0)
			love.graphics.rectangle("fill", question2_1.x, question2_1.y , question2_1.w - question2_1.x, question2_1.h - question2_1.y, 10, 10)
		    menu.over = 1
			love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("Exit", 68, 412)
		elseif menu.position2_1 then
		    love.graphics.setColor(255, 0, 0)
			love.graphics.rectangle("fill", question2_1.x, question2_1.y , question2_1.w - question2_1.x, question2_1.h - question2_1.y, 10, 10)
	        love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("Exit", 68, 412)
		end -- 1
		if not menu.position2_2 then 
	        love.graphics.setColor(0, 205, 205, 100)   
		    love.graphics.rectangle("fill", question2_2.x, question2_2.y , question2_2.w - question2_2.x, question2_2.h - question2_2.y, 10, 10)
		    love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("cancle", 155, 412)
		elseif menu.down2_2 then
		    love.graphics.setColor(0, 255, 0)
			love.graphics.rectangle("fill", question2_2.x, question2_2.y , question2_2.w - question2_2.x, question2_2.h - question2_2.y, 10, 10)
		    menu.button = 0
			love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("cancle", 155, 412)
		elseif menu.position2_2 then
		    love.graphics.setColor(255, 0, 0)
			love.graphics.rectangle("fill", question2_2.x, question2_2.y , question2_2.w - question2_2.x, question2_2.h - question2_2.y, 10, 10)
	        love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font1)
			love.graphics.print("cancle", 155, 412)
		end -- 2
	
	else 
	    -- 主菜单
	    -- 第二个按钮功能设置
	    if not menu.position2 then
	        love.graphics.setColor(0, 205, 205,100)
	        love.graphics.rectangle("fill", question2.x, question2.y , question2.w - question2.x, question2.h - question2.y, 10, 10)
            love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font)
			love.graphics.print("Exit", 105, 425)
		elseif menu.down2 then
	        love.graphics.setColor(0, 255, 0)
	        love.graphics.rectangle("fill", question2.x, question2.y , question2.w - question2.x, question2.h - question2.y, 10, 10)
	        love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font)
			love.graphics.print("Exit", 105, 425)
			menu.button = 2
	    elseif menu.position2 then
	        love.graphics.setColor(255, 0, 0)
	        love.graphics.rectangle("fill", question2.x, question2.y , question2.w - question2.x, question2.h - question2.y, 10, 10)
	        love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font)
			love.graphics.print("Exit", 105, 425)
		end
	    -- 第一个按钮功能设置
	    if not menu.position1 then 
	        love.graphics.setColor(0, 205, 205,100)
	        love.graphics.rectangle("fill", question1.x, question1.y , question1.w - question1.x, question1.h - question1.y, 10, 10)
	        love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font)
			love.graphics.print("Change", 75, 220)
		elseif menu.down1 then
	        love.graphics.setColor(0, 255, 0)
	        love.graphics.rectangle("fill", question1.x, question1.y , question1.w - question1.x, question1.h - question1.y, 10, 10)
	        love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font)
			love.graphics.print("Change", 75, 220)
			menu.button = 1
	    elseif menu.position1 then
	        love.graphics.setColor(255, 0, 0)
	        love.graphics.rectangle("fill", question1.x, question1.y , question1.w - question1.x, question1.h - question1.y, 10, 10)
	        love.graphics.setColor(255, 255, 255)
			love.graphics.setFont(font)
			love.graphics.print("Change", 75, 220)
		end 
	end
	-- 画出移动物体
	love.graphics.setColor(255, 0, 0, 255)
	love.graphics.circle("fill", ball.x, ball.y, ball.r)
	
end